﻿using System;
using System.Windows.Forms;
using Letspirate.Common;
using Letspirate.Utilities.ExtensionMethods;

namespace UnknownDll.MapGenerator
{
    public partial class MapGeneratorForm : Form
    {
        public MapGeneratorForm()
        {
            InitializeComponent();

            //TODO: Localization
            ColorIdMappingsLabel.Text = "Path to color-id mappings file";
            //TODO: Localization
            IdMapLabel.Text = "Path to id map file";
            //TODO: Localization
            RiversMapLabel.Text = "Path to rivers map file";
            //TODO: Localization
            ProvincesMapLabel.Text = "Path to provinces map file";
        }

        private void ColorIdMappingsButtonClick(object sender, EventArgs e)
        {
            var result = ColorIdMappingsOpenFileDialog.ShowDialog();

            if (result == DialogResult.OK)
                ColorIdMappingsTextBox.Text = ColorIdMappingsOpenFileDialog.FileName;
        }

        private void IdMapButtonClick(object sender, EventArgs e)
        {
            var result = IdMapOpenFileDialog.ShowDialog();

            if (result == DialogResult.OK)
                IdMapTextBox.Text = IdMapOpenFileDialog.FileName;
        }

        private void RiversMapButtonClick(object sender, EventArgs e)
        {
            var result = RiversMapOpenFileDialog.ShowDialog();

            if (result == DialogResult.OK)
                RiversMapTextBox.Text = RiversMapOpenFileDialog.FileName;
        }

        private void ProvincesMapButtonClick(object sender, EventArgs e)
        {
            var result = ProvincesMapOpenFileDialog.ShowDialog();

            if (result == DialogResult.OK)
                ProvincesMapTextBox.Text = ProvincesMapOpenFileDialog.FileName;
        }

        private void GenerateMapButtonClick(object sender, EventArgs e)
        {
            throw new NotImplementedException();
            
            DisableButtons();
            LogTextBox.Clear();

            if (ValidateForm() == false)
            {
                EnableButtons();
                return;
            }

            

            //TODO: Localization
            LogTextBox.AppendText("Done!");

            EnableButtons();
        }

        private bool ValidateForm()
        {
            var result = true;

            if (ColorIdMappingsTextBox.Text.IsEmpty() == true)
            {
                result = false;
                //TODO: Localization
                LogTextBox.AppendText("Color-id mappings file is not selected\n");
            }

            if (IdMapTextBox.Text.IsEmpty() == true)
            {
                result = false;
                //TODO: Localization
                LogTextBox.AppendText("Id map file is not selected\n");
            }

            if (RiversMapTextBox.Text.IsEmpty() == true)
            {
                result = false;
                //TODO: Localization
                LogTextBox.AppendText("Rivers map file is not selected\n");
            }

            if (ProvincesMapTextBox.Text.IsEmpty() == true)
            {
                result = false;
                //TODO: Localization
                LogTextBox.AppendText("Provinces map file is not selected\n");
            }

            return result;
        }

        private void DisableButtons()
        {
            ColorIdMappingsButton.Enabled = false;
            IdMapButton.Enabled = false;
            RiversMapButton.Enabled = false;
            ProvincesMapButton.Enabled = false;
            GenerateMapButton.Enabled = false;
        }

        private void EnableButtons()
        {
            ColorIdMappingsButton.Enabled = true;
            IdMapButton.Enabled = true;
            RiversMapButton.Enabled = true;
            ProvincesMapButton.Enabled = true;
            GenerateMapButton.Enabled = true;
        }

        private void AboutToolStripMenuItemClick(object sender, EventArgs e)
        {

        }
    }
}
